Page({
  data: { 
    indicatorDots: true,
    autoplay: true,
    interval: 2500,
    duration: 500,
    address: '杭州市余杭区良睦路梦想小镇1288号2号楼',
    indicatorActiveColor: '#eee',
    indicatorColor: 'rgba(255, 255, 255, .3)',
    active: true,
    isShow: true,
    iconAddr: '../../images/icon_addr.png',
    roomList: {},
    showModal: false,
  },
  onLoad: function (option) {
    // 生命周期函数--监听页面加载
    active: (option.active == "true" ? true : false);
    isShow: (option.isShow == "true" ? true : false);
    var that = this;
    // 模拟数据
    var data = {
      'imgUrls': [
        'http://wx.resthour.net/static/images/banners/banner_2_2.jpg',
        'http://wx.resthour.net/static/images/banners/banner_2_3.jpg',
        'http://wx.resthour.net/static/images/banners/banner_2_4.jpg'
      ],
      'roomList': [
        {
          'roomCode': 1, 'roomName': '智能大床房', 'roomPrice': '418', 'count': 10, 'area': 55,
         'imgSrc': 'http://wx.resthour.net/static/images/roomtypes/rtype_2_1.jpg'},
        {
          'roomCode': 2, 'roomName': '智能双床房', 'roomPrice': '418', 'count': 10, 'area': 68,
          'imgSrc': 'http://wx.resthour.net/static/images/roomtypes/rtype_2_2.jpg' },
        {
          'roomCode': 3, 'roomName': '智慧大床房', 'roomPrice': '528', 'count': 0, 'area': 55,
          'imgSrc': 'http://wx.resthour.net/static/images/roomtypes/rtype_2_3.jpg' },
        {
          'roomCode': 4, 'roomName': '智慧双床房', 'roomPrice': '528', 'count': 12, 'area': 68,
          'imgSrc': 'http://wx.resthour.net/static/images/roomtypes/rtype_2_4.jpg' },
        {
          'roomCode': 5, 'roomName': '智趣套房(复式)', 'roomPrice': '738', 'count': 0, 'area': 88,
          'imgSrc': 'http://wx.resthour.net/static/images/roomtypes/rtype_2_5.jpg'},
        { 
          'roomCode': 6, 'roomName': '智趣套房(单层)', 'roomPrice': '738', 'count': 8, 'area': 68,
          'imgSrc': 'http://wx.resthour.net/static/images/roomtypes/rtype_2_6.jpg' },
        {
          'roomCode': 7, 'roomName': '梦想园景套房', 'roomPrice': '588', 'count': 0, 'area': 68,
          'imgSrc': 'http://wx.resthour.net/static/images/roomtypes/rtype_2_7.jpg' },
        {
          'roomCode': 8, 'roomName': '梦想复式LOFT', 'roomPrice': '588', 'count': 0, 'area': 88,
          'imgSrc': 'http://wx.resthour.net/static/images/roomtypes/rtype_2_8.jpg' },
        {
          'roomCode': 9, 'roomName': '测试类型', 'roomPrice': '388', 'count': 0, 'area': 68,
          'imgSrc': 'http://wx.resthour.net/static/images/roomtypes/rtype_2_9.jpg' },

      ]
    };
    // 数据请求
    // wx.request({
    //   url: 'http://testcloud.resthour.net/wx/hotel/getRoomType?hotelId=' + 2 + '&adate=' + option.adate + '&ddate=' + option.ddate,
    //   data: data,
    //   success:function(res){
    //     console.log(res);
    //     that.setData({
    //       roomList: res.data.data
    //     })
    //   }
    // })
    that.setData({
      imgUrls: data.imgUrls,
      roomList: data.roomList
    }); 
  },
 
  // 添加class
  onChangeActive: function () {
    var _that = this;
    _that.setData({
      active: (!_that.data.active),
      isShow: (!_that.data.isShow),
    })
  },
  onChangeOPen: function (e) {
    var that = this;
    var toggleBtnVal = that.data.uhide;
    var itemId = e.currentTarget.id;
    if (toggleBtnVal == itemId) {
      that.setData({
        uhide: 0
      })
    } else {
      that.setData({
        uhide: itemId,
        roomList: that.data.roomList
      })
    }
  },
  // 打开地图
  openLocation() {
    var that = this;
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success: function (res) {
        wx.openLocation({
          latitude: 30.285920,
          longitude: 120.005830,
          scale: 16,
          name: that.data.hotelName,
          address: that.data.address
        })
      },
      fail: function (res) { //用户点了“拒绝”
        wx.showModal({ // 向用户提示需要权限才能继续
          // title: '提示',
          content: '地图功能需要您提供地理位置授权！',
          success: function (res) {
            if (res.confirm) {
              wx.openSetting({
                success: function (res) { // 如果成功打开授权
                  if (res.authSetting["scope.userLocation"]) {
                    wx.openLocation({
                      latitude: 30.285920,
                      longitude: 120.005830,
                      scale: 16,
                      name: that.data.hotelName,
                      address: that.data.address
                    })
                  }
                  else {// 如果用户依然拒绝授权

                  }
                },
                fail: function () { //调用失败，授权登录不成功
                  fail()
                }
              })
            } else if (res.cancel) {
              return false
            }
          }
        })

      }
    })
  },
  // 拨打电话
  calling:function(){
    wx.makePhoneCall({
      phoneNumber: '0571-88616611',
      file: function(){
        wx.showToast({
          title: '电话维修中！',
          icon: 'none',
          duration: 1500
        })
       
      }
    })
  },
 // 弹窗
  showDialogBtn: function (e) {
    var that = this;
    that.setData({
      showModal: true
    })
   
    // var _index = e.currentTarget.dataset.index,
    //     roomName = this.data.roomList[_index].roomName,
    //     hotelId =  this.options.hotelId,
    //     adata = this.options.adate,
    //     ddate = this.options.ddate;
    // wx.request({
    //   url: 'http://testcloud.resthour.net/wx/hotel/getRoomsByType?hotelId=' + hotelId 
    //                 + '&startDate=' + adata + '&endDate=' + ddate + '&roomType=' + roomName,
    //   //    header: {
    //   //      "Content-Type" : "application/x-www-form-urlencoded",
    //   //    },
    //   // method: 'post',
    //   success: function (res) {
      
       
    //   }
    // })
  
   
  },
  /**
   * 弹出框蒙层截断touchmove事件
   */
  preventTouchMove: function () {
  },
  /**
   * 隐藏模态对话框
   */
  hideModal: function () {
    this.setData({
      showModal: false
    });
  },
  /**
   * 对话框取消按钮点击事件
   */
  onCancel: function () {
    this.hideModal();
  },
  /**
   * 对话框确认按钮点击事件
   */
  onConfirm: function (e) {
    var that= this;
    var roomType = e.currentTarget.dataset.type;
    var _count = e.currentTarget.dataset.count;
    var _price = e.currentTarget.dataset.price;
    var _in = this.options.adate.slice(0, 10);
    var _out = this.options.ddate.slice(0, 10);
    if(_count == 0) {
      wx.showToast({
        title: '没有可用房间！',
        icon: 'none',
        duration: 800
      })
      setTimeout(function(){
        that.hideModal();
      },800)
    }else {
      that.hideModal();
      wx.navigateTo({
        url: '../submitOrder/submitOrder?roomType=' + roomType + '&adate=' + _in + '&ddate=' + _out + '&roomPrice=' + _price ,
      });
    }
  }
})